//
//  SwiftViewController.swift
//  TotalDemo
//
//  Created by gujian on 16/8/16.
//  Copyright © 2016年 gujian. All rights reserved.
//

import UIKit

class SwiftViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.whiteColor();
        self.setupView();
    }

    func setupView() -> Void {
        var marginLeft = CGFloat.init(0.0);
        var marginTop = CGFloat.init(0.0);
        
        for i in 1...10{

            let view = UIView.init(frame: CGRectMake(marginLeft, marginTop, 100, 100));
            view.backgroundColor = UIColor.redColor();
            self.view.addSubview(view);
            
            if i % 3 == 0 && i > 0 {
                marginLeft = CGFloat.init(0.0);
                marginTop = marginTop + 100 + 10;
            }else{
                 marginLeft = marginLeft + 10 + 100;
            }
            

            
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
